/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2013/05/12
* File: SceneGraph.h
* Blog: http://www.cnblogs.com/zengqh/
**/

#pragma once

#include "SceneNode.h"

namespace HY
{
class SceneGraph
{
public:
	typedef std::tr1::unordered_map<std::string, SceneNode*>		NodeMap;
	typedef std::vector<SceneNode*>							NodeList;
	typedef SceneNode*										(*CreatorType)();
	typedef std::tr1::unordered_map<ClassType, CreatorType>			CreatorMap;

public:
	SceneGraph();
	~SceneGraph();

public:
	void setName(const std::string& name)
	{
		name_ = name;
	}

	const std::string& getName() const
	{
		return name_;
	}

public:
	SceneNode* createSceneNode(ClassType type, const std::string& name);
	template<class T> T* createSceneNode(const std::string& name)
	{
		return static_cast<T*>(createSceneNode(HY_CLASS_TYPE(T), name));
	}



protected:
	CreatorType findCreator( ClassType type ) const;

	template<class T>
	void registerCreator();

	void init();

	template<class T>
	static SceneNode* _createSceneNode();

protected:
	std::string		name_;
	CreatorMap		creator_map_;
};
}